﻿using Albatross.WPF.Common;
using Albatross.WPF.Common.ViewModels;
using Microsoft.SharePoint.Client;
using Microsoft.SharePoint.Client.Workflow;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Albatross.SharePoint.Explorer.ViewModels {
	public class ClientObjectFactory {
		public static ClientObjectViewModel GetViewModel(ClientContext context, string name, Type type, ClientObject clientObject) {
			ClientObjectViewModel vm;
			if (type == typeof(Site)) {
				vm = new SiteViewModel(context, name, (Site)clientObject);
			}else if(type == typeof(Feature)){
				vm = new FeatureViewModel(context, name, (Feature)clientObject);
			}else if(type == typeof(Web)){
				vm = new WebViewModel(context, name, (Web)clientObject);
			}else if(type == typeof(User)){
				vm = new UserViewModel(context, name, (User)clientObject);
			}else if(type == typeof(Group)){
				vm = new GroupViewModel(context, name, (Group)clientObject);
			}else if(type == typeof(ContentType)){
				vm = new ContentTypeViewModel(context, name, (ContentType)clientObject);
			}else if(type == typeof(List)){
				vm = new ListViewModel(context, name, (List)clientObject);
			}else if(type.IsSubclassOf(typeof(Field)) || type == typeof(Field)){
				vm = new FieldViewModel(context, name, (Field)clientObject);
			}else if(type == typeof(RecycleBinItem)){
				vm = new RecycleBinItemViewModel(context, name, (RecycleBinItem)clientObject);
			}else if(type == typeof(Folder)){
				vm = new FolderViewModel(context, name, (Folder)clientObject);
			}else if(type == typeof(File)){
				vm = new FileViewModel(context, name, (File)clientObject);
			}else if(type == typeof(EventReceiverDefinition)){
				vm = new EventReceiverViewModel(context, name, (EventReceiverDefinition)clientObject);
			}else if(type == typeof(NavigationNode)){
				vm = new NavigationNodeViewModel(context, name, (NavigationNode)clientObject);
			}else if(type == typeof(FieldLink)){
				vm = new FieldLinkViewModel(context, name, (FieldLink)clientObject);
			}else if(type == typeof(RoleDefinition)){
				vm = new RoleDefinitionViewModel(context, name, (RoleDefinition)clientObject);
			}else if(type == typeof(WorkflowTemplateViewModel)){
				vm = new WorkflowTemplateViewModel(context, name, (WorkflowTemplate)clientObject);
			}else if(type == typeof(Form)){
				vm = new FormViewModel(context, name, (Form)clientObject);
			}else if(type == typeof(RoleAssignment)){
				vm = new RoleAssignmentViewModel(context, name, (RoleAssignment)clientObject);
			}else if(type == typeof(Principal)){
				vm = new PrincipalViewModel(context, name, (Principal)clientObject);
			}else if(type == typeof(View)){
				vm = new ViewViewModel(context, name, (View)clientObject);
			}else if(type == typeof(ListTemplate)){
				vm = new ListTemplateViewModel(context, name, (ListTemplate)clientObject);
			}else if(type == typeof(WorkflowTemplate)){
				vm = new WorkflowTemplateViewModel(context, name, (WorkflowTemplate)clientObject);
			}else if(type == typeof(Microsoft.SharePoint.Client.TimeZone)){
				vm = new TimeZoneViewModel(context, name, (Microsoft.SharePoint.Client.TimeZone)clientObject);
			}else if (clientObject is ClientObjectCollection) {
				vm = new ClientObjectCollectionViewModel(context, name, (ClientObjectCollection)clientObject);
			} else {
				vm = new ClientObjectViewModel(context, name, clientObject);
			}
			return vm;
		}
	}
}
